/**************************************************************************
** Written by Ron Olson in Chicago, Illinois
**      11/29/2010 2010
**
** Gratis to you. Enjoy.
**************************************************************************/

#include "solverdifference.h"

SolverDifference::SolverDifference(const map<string, vector<cache> >& workingDataSet) : Solver(workingDataSet)
{
}

void SolverDifference::findDifferentCaches(void)
{
    bool firstTime = true;

    for (std::map<string, vector<cache> >::const_iterator mapIt = dataSet.begin(); mapIt
            != dataSet.end(); ++mapIt)
    {
        // If this is the first pass, just load the result set with this vector
        if (firstTime)
        {
            differentCaches = mapIt->second;
            firstTime = false;
        }
        else
        {
            vector<cache> tempSet = differentCaches;
            vector<cache> tempResultSet;
            set_difference(mapIt->second.begin(), mapIt->second.end(),
                             tempSet.begin(), tempSet.end(),
                             back_inserter(tempResultSet), cacheSorter);

            differentCaches = tempResultSet;
        }
    }
}

vector<cache>& SolverDifference::getDifferentCaches()
{
    return differentCaches;
}

